package com.cvit.service;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cvit.dao.vMajorMapper;
import com.cvit.model.ExcelBean;
import com.cvit.model.vMajor;
import com.cvit.utils.ExcelUtil;

@Service
public class vMajorService {

	@Autowired
	vMajorMapper vmajorMapper;

	public List<vMajor> getvMajorAll() {
		List<vMajor> vmajor = vmajorMapper.selectByExample(null);
		return vmajor;
	}
	
	/**
	 * 导出Excel表
	 * */
	public XSSFWorkbook exportExcelInfo(String vmajorData) throws Exception {  
	    //根据条件查询数据，把数据装载到一个list中  
	    List<vMajor> list = vmajorMapper.selectByExample(null);
	    List<ExcelBean> excel=new ArrayList<>();
	    Map<Integer,List<ExcelBean>> map=new LinkedHashMap<>();
	    XSSFWorkbook xssfWorkbook=null;
	    //设置标题栏
	    excel.add(new ExcelBean("专业名称","major",0));
	    excel.add(new ExcelBean("人数","num",0));
	    map.put(0, excel);
	    String sheetName = vmajorData;
	    //调用ExcelUtil的方法
	    xssfWorkbook = ExcelUtil.createExcelFile(vMajor.class, list, map, sheetName);
	    return xssfWorkbook;
	}
	
}
